/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities.question;

import entities.Proposition;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author loic.vaugeois
 */
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type",discriminatorType=DiscriminatorType.STRING)
@Table(name="question")
@NamedQueries({
@NamedQuery(name = "AbstractQuestion.findLastIdQuestion", query
        = "SELECT max(aq.id) FROM AbstractQuestion aq "),
@NamedQuery(name = "AbstractQuestion.findAllQuestion", query
        = "SELECT aq FROM AbstractQuestion aq ")
})
public abstract class AbstractQuestion implements Serializable {

/*
 *********************ATTRIBUTS
 */
    @Id
    @Column(name="id_question")
    private long id;

    /**
     * Intitulé de la Question
     */
    @Column(name="intitule")
    private String intitule;



/*
 *********************GETTER SETTER
 */

    public String getIntitule() {
        return intitule;
    }

    /**
     * Liste des Propositions de réponse à une question (peut être null dans le cas d'une réponse ouverte.
     * @return
     * @throws UnsupportedOperationException
     */
    public List<Proposition> getPropositions() throws UnsupportedOperationException{
        throw new UnsupportedOperationException("Cette question n'amène pas de propositions");
    }   

    public void setPropositions(List<Proposition> listePropositions) {
        throw new UnsupportedOperationException("Cette question ne peut avoir aucune proposition.");
    }

    public void setIntitule(String intituleQuestion) {
        if (intituleQuestion==null) throw new IllegalArgumentException("Un intitulé de question ne peut être nulle");
        if (intituleQuestion.isEmpty()) throw new IllegalArgumentException("Un intitulé de question ne peut être vide");
        this.intitule = intituleQuestion;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

/*
 *********************CONSTRUCTEURS
 */
    /**
     * Constructeur AbstractQuestion
     * @param intituleQuestion
     */
    public AbstractQuestion(String intituleQuestion) {
        this.intitule = intituleQuestion;
    }
    /**
     * Constructeur nécessaire à JPA
     */
    public AbstractQuestion(){
        
    }

    @Override
    public String toString() {
        return getIntitule();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final AbstractQuestion other = (AbstractQuestion) obj;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 79 * hash + (int) (this.id ^ (this.id >>> 32));
        return hash;
    }

}
